/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.report;

import au.com.createpdf.CreateInventoryReport;
import com.lowagie.text.DocumentException;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import database.InventoryDAO;
import database.StaffAuthenticationDAO;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import model.Product;
import model.Staff;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Trang
 */
@Namespace("/Administration/Report")
public class InventoryReport extends ActionSupport {

    private List<Product> products = new ArrayList<Product>();
    private String date;

    public List<Product> getProducts() {
        return products;
    }

    public void setProducts(List<Product> products) {
        this.products = products;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    @Action(value = "inventory-report", results = {
        @Result(name = "success", location = "/manageReport/w_inventoryReport.jsp")
    })
    public String OrderManagement() throws IOException, DocumentException {
        
        Map session = ActionContext.getContext().getSession();
        Staff staff = (Staff) session.get("staff");
        session.put("product", 1);
        Date createdate = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        date = dateFormat.format(createdate);
        String RESULT = "E:\\InventoryReport_"+staff.getFirstname()+".pdf";
        products = new InventoryDAO().getProductForInventory(4);
        new CreateInventoryReport().createPdf(date, RESULT, products, staff);
        new StaffAuthenticationDAO().addAction("Create Inventory Report", staff.getIdStaff());
        return SUCCESS;
    }
}
